package com.byCreation.t_globe;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.aretha.slidemenu.SlideMenu;
import com.byCreatetion.adabter.MainmenuListAdapter;
import com.byCreation.Control.Control;
import com.byCreation.Control.LDObservableScrollView;
import com.byCreation.Control.MenuData;
import com.byCreation.Control.SliderMenuLeft;
import com.byCreation.Control.LDObservableScrollView.LDObservableScrollViewListener;

import com.byCreation.Control.SliderMenuLeft.informationListAdapter;

import com.byCreation.Profile.CompareActivity;
import com.byCreation.Profile.MyBookmarkActivity;
import com.byCreation.Profile.MyDiscountActivity;
import com.byCreation.Profile.MyHistoryActivity;
import com.byCreation.Profile.MyNoteActivity;
import com.byCreation.Profile.MySettingActivity;
import com.byCreation.Profile.MyprofileActivity;
import com.byCreation.Profile.TglobeAppActivity;
import com.byCreation.t_globe.R;


import com.capricorn.ArcMenu;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import com.squareup.picasso.Picasso;





import Myclass.AllIntent;
import Myclass.ConnectInternet;
import Parser.HttpGetJson;
import Parser.SendToBD;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Html;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import animation.ResizeWidthAnimation;

public class ContentActivity  extends BaseSlideMenuActivity implements LDObservableScrollViewListener,OnClickListener {

	
	
	
	
	
	
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		
		ReSetMainMenu();
		
		super.onRestart();
	}

	public Activity THIS;
	  
	// ==================Main Menu=======================
			private ListView Mainmenu_lstView;
			private MainmenuListAdapter Mainmenu_adapter;
			public  ArrayList<HashMap<String, Object>> Mainmenu_MyArrList;
			private HashMap<String, Object> Mainmenu_map = new HashMap<String, Object>();
			private ProgressDialog mProgressDialog;
			private TextView Mainmenu_txt_title_menu;
			private LayoutParams Mainmenu_lstView_params;
			
//			public  String Mainmenu_page_title="เกาะพะงัน";
//			public  String Mainmenu_Data_Dafalt="";
//			public  ArrayList<MenuData> Mainmenu_List_DATA_History = new ArrayList<MenuData>();
//			public  ArrayList<String> Mainmenu_List_Menu_Title = new ArrayList<String>();
			
		
			
			
			public  String information_page_title="t-Globe Highlights";
			public  String information_Data_Dafalt="";
			public  ArrayList<MenuData> information_List_DATA_History = new ArrayList<MenuData>();
			public  ArrayList<String> information_List_Menu_Title = new ArrayList<String>();
			
			
		
	
		//SliderMenu
		private SlideMenu mSlideMenu;
		
		
		
		//=========menu
				private FrameLayout lay_munu;
				private Animation anim_menu_show,anim_menu_hide;
				private ArcMenu  arc_menu;
				private static final int[] ITEM_DRAWABLES = { 
					R.drawable.main_button_sub_btn_1,R.drawable.main_button_sub_btn_2,
					R.drawable.main_button_sub_btn_3,R.drawable.main_button_sub_btn_4,
					R.drawable.main_button_sub_btn_5, };
				
				
				private  Animation anim_in,anim_out;
				
			
			
				
				
				private ArrayList<HashMap<String, Object>> MyArrList_content = new ArrayList<HashMap<String, Object>>();
				private ArrayList<HashMap<String, Object>> MyArrList_card = new ArrayList<HashMap<String, Object>>();

				private ArrayList<HashMap<String, Object>> MyArrList2 = new ArrayList<HashMap<String, Object>>();
				
				private HashMap<String, Object> map_content = new HashMap<String, Object>();
				private HashMap<String, Object> map_card = new HashMap<String, Object>();

				
				
				private ImageView img_gotocard;
				private ProgressBar progressBar1;
		
		
		
				
				
				//Profile
				private ImageView img_profile_menu1,img_profile_menu2,img_profile_menu3,
				img_profile_menu4,img_profile_menu5,img_profile_menu6,img_profile_menu7,
				img_profile_menu8,img_profile_menu9,img_user;
				
				private LinearLayout txt_next,txt_register;
				private FrameLayout Laylogin;
				private ConnectInternet connect=new ConnectInternet(ContentActivity.this);
				
				
				// ===============GoogleAnalytics==============
				private GoogleAnalytics mGaInstance;
				private Tracker mGaTracker;
				// =============================================
	// ===================================googleAnalytics=============================
			@Override
			public void onStart() {
				super.onStart();
				// The rest of your onStart() code.
				EasyTracker.getInstance().activityStart(this); // Add this method.
				mGaTracker.sendView("Content Screen");

			}

		
				
	
		@Override
		public void onContentChanged() {
			super.onContentChanged();
			Log.e("Test", "SlideMenuAttribute");
			
			setSlideRole(R.layout.activity_content);
			setSlideRole(R.layout.layout_primary_menu);
			setSlideRole(R.layout.fagment_profile);
			SetSliderMenu();
			
			
			// =============================GoogleAnalytics=========================
			mGaInstance = GoogleAnalytics.getInstance(this);
			mGaTracker = mGaInstance.getTracker(Control.IDGoogleanalytics);
	
			
			
			if (android.os.Build.VERSION.SDK_INT > 9) {
				StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
						.permitAll().build();
				StrictMode.setThreadPolicy(policy);
			}
			
			
			if(Control.Call_From_Note&&new ConnectInternet(this).checkInternetConnection())
				new Load_DATANote().execute();
			
			
			
			SetView();
			SetViewProfile();
			
			SetMainMenu();
			Setinformation();
			
			
			
			if(new ConnectInternet(this).checkInternetConnection())
				new Load_AddToHistory().execute();

		}

		SliderMenuLeft slide;
		private void SetSliderMenu() {
			// TODO Auto-generated method stub
			mSlideMenu = getSlideMenu();
			THIS=ContentActivity.this;
			mSlideMenu.setEdgeSlideEnable(true);
			mSlideMenu.setEdgetSlideWidth(Control.setEdgetSlideWidth);
			Display display = getWindowManager().getDefaultDisplay();
			int width = display.getWidth(); // deprecated
			int height = display.getHeight(); // deprecated

			
			RelativeLayout rl = (RelativeLayout) findViewById(R.id.R1);
			RelativeLayout r2 = (RelativeLayout) findViewById(R.id.R2);

			rl.getLayoutParams().width = width - 100;
			r2.getLayoutParams().width = width - 100;
			
		}
		
		
		private ImageView img_title;
		private void SetView() {
			
			anim_in = AnimationUtils.loadAnimation(ContentActivity.this, R.anim.anim_ace_show);
			anim_out= AnimationUtils.loadAnimation(ContentActivity.this, R.anim.anim_ace_hide);
			anim_menu_show = AnimationUtils.loadAnimation(ContentActivity.this, R.anim.anim_menu_show);
			anim_menu_hide = AnimationUtils.loadAnimation(ContentActivity.this, R.anim.anim_menu_hide);
			
			//=====Arc menu
			arc_menu=(ArcMenu)findViewById(R.id.arc_menu);
			initArcMenu(arc_menu, ITEM_DRAWABLES);
			
			
			
			//===========top menu
			ImageView img_mainmenu=(ImageView)findViewById(R.id.img_mainmenu);
			img_mainmenu.setOnClickListener(this);
			ImageView img_profile=(ImageView)findViewById(R.id.img_profile);
			img_profile.setOnClickListener(this);
			ImageView img_home=(ImageView)findViewById(R.id.img_home);
			img_title=(ImageView)findViewById(R.id.img_title);
			
			
			img_home.setOnClickListener(this);
			
			 if(Control.Loginstatus)
			 {
				 try {
						
						
						

					 
						if(Control.Img_profile.equals(""))
						{
							img_profile.setImageResource(R.drawable.btn_menu_top_righ);

						}
						else
						{
							Bitmap myBitmap = BitmapFactory.decodeFile(Control.Img_profile_Path);
							img_profile.setImageBitmap(myBitmap);
						}
						
						
						
						} catch (Exception e) {
							img_profile.setImageResource(R.drawable.btn_menu_top_righ);
						}
					
			 }
			
			
			 lay_munu=(FrameLayout)findViewById(R.id.lay_munu);
			 lay_munu.startAnimation(anim_menu_show);
			 
			//======
			 progressBar1=(ProgressBar)findViewById(R.id.progressBar1);
			 
			 
			 
			
		txt_title=(TextView)findViewById(R.id.txt_title);
				
			
			 
			SetScollView();
		}
		
		
		
		
		float Y_Down=0.0f;
		float Y_Move=0.0f;
		float Y_Up=0.0f;
		private void SetScollView()
		{
			
			
		/*	img_gotocard=(ImageView)v.findViewById(R.id.img_gotocard);
			img_gotocard.setOnClickListener(this);*/
			
			
			    LDObservableScrollView scroll_content=(LDObservableScrollView)findViewById(R.id.scrollView_content);
				scroll_content.setScrollViewListener(this);
				
				
				
				scroll_content.setOnTouchListener(new OnTouchListener() {
		
			        public boolean onTouch(View v, MotionEvent event) {
		
			            if (event.getAction() == MotionEvent.ACTION_DOWN) {
			            	
			            	
			            	//Log.e("TG","y Down="+event.getY());
			            	Y_Down=event.getY();
			            }
			            
			            
			            if (event.getAction() == MotionEvent.ACTION_MOVE) {
			            	
			            	
			            	//Log.e("TG","y Move="+event.getY());
			            	Y_Move=event.getY();
			            	
			            	
			            	
			            		
			            }
			            
			            if(event.getAction() == MotionEvent.ACTION_UP)
			            {
			            	
			            	if(Y_Down-Y_Move>30&&arc_menu.getVisibility()==View.VISIBLE&&diff!=0)
			            	{
			            		HideMenu();
			            	}
			            	if(Y_Down-Y_Move<50&&arc_menu.getVisibility()==View.INVISIBLE)
			            	{
			            		ShowMenu();
			            	}	
			            	
			            }
			            return false;
			        }
				});  
			        
		
		}
	    private void ShowMenu() {
		// TODO Auto-generated method stub
			arc_menu.setVisibility(View.VISIBLE);
			arc_menu.startAnimation(anim_in);
			
			
			lay_munu.setVisibility(View.VISIBLE);
			lay_munu.startAnimation(anim_menu_show);
		
		}
		private void HideMenu() {
			// TODO Auto-generated method stub
			arc_menu.setVisibility(View.INVISIBLE);
			arc_menu.startAnimation(anim_out);

			lay_munu.setVisibility(View.INVISIBLE);
			lay_munu.startAnimation(anim_menu_hide);
		}
		
		private void initArcMenu(ArcMenu menu, int[] itemDrawables) {
	        final int itemCount = itemDrawables.length;
	        for (int i = 0; i < itemCount; i++) {
	            ImageView item = new ImageView(ContentActivity.this);
	            item.setImageResource(itemDrawables[i]);

	            final int position = i;
	            menu.addItem(item, new OnClickListener() {

	                @Override
	                public void onClick(View v) {
	                	
	                	if(position==0)
	                	{
	                		Control.Pointers="Content";
	                		startActivity(new Intent(ContentActivity.this,MapActivity.class));
	                		ContentActivity.this.overridePendingTransition (R.anim.fade_in, R.anim.fade_out);ContentActivity.this.overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
	                		
	                	}
	                	if(position==1)//note
	                	{
	                		if(new ConnectInternet(ContentActivity.this).checkInternetConnection())
	                		new Load_DATANote().execute();
	                		
	                   	}
	                	if(position==2)//photo
	                	{
	                		startActivity(new Intent(ContentActivity.this,PhotoActivity.class));
	                		 ContentActivity.this.overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
	                	}
	                	if(position==3)//bookmark
	                	{
	                		Dialog_YesNo(R.drawable.app_icon, "Bookmark", "");
	                		// new Load_AddBookmark().execute();
	                	}
	                	if(position==4)//Share
	                	{
	                		AllIntent intent=new AllIntent(ContentActivity.this);
	                		intent.ShareDG("http://www.t-globe.com/"+Control.page_id, "");
	                	}
	                }
	            });
	        }
	    }

		
		
		private int diff=-1;
		@Override
		public void onScrollChanged(LDObservableScrollView scrollView, int x,int y, int oldx, int oldy) {
			// TODO Auto-generated method stub
			View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
			 diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
			if(diff==0)
			{
				//Log.e("TG", "SCROLL END");
				//ShowMenu();
			}
			
		}

		public  void Dialog_YesNo(int icon ,String title,String mess)
		{
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(ContentActivity.this);
			 
	        // Setting Dialog Title
	        alertDialog.setTitle(title);
	 
	        // Setting Dialog Message
	        alertDialog.setMessage(mess);
	 
	        // Setting Icon to Dialog
	        alertDialog.setIcon(icon);
	 
	        // Setting Positive "Yes" Button
	        alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog,int which) {
	            	
	             //
	             
	              
	              if(new ConnectInternet(ContentActivity.this).checkInternetConnection())
	              {
	            	  new Load_AddBookmark().execute();
	              }
	            	 dialog.cancel();
	            	  
	            	
	            }
	        });
	 
	        // Setting Negative "NO" Button
	        alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int which) {
	            // Write your code here to invoke NO event
	            
	            	dialog.cancel();
	            }
	        });
	 
	        // Showing Alert Message
	        alertDialog.show();
		}
		class Load_AddBookmark extends AsyncTask<Object, Integer, Object> {

		  

			private ProgressDialog mProgressDialog2;
			private String title,content,images,date,link,result,desc;
			private boolean Cancle=false;
			
			  @Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				  Cancle=true;
				super.onCancelled();
			}
			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					JSONObject jsonObj=null;
					jsonObj = new JSONObject(HttpGetJson.GetJson(Control.getAPI_AddTobookmark_Page(Control.page_id, Control.UserName),Control.user,Control.pass));
					
				//Log.e("TG",(HttpGetJson.GetJson(Control.getAPI_AddTobookmark(Control.page_id, Control.UserName),Control.user,Control.pass)));

				
			    desc=jsonObj.getString("desc");
			  
			    
			    
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
					 
				return null;
			}

			@Override
			protected void onPreExecute() {

				 //=====================ProgressDialog==========================
				if(mProgressDialog2==null)
				{
			        mProgressDialog2 = new ProgressDialog(ContentActivity.this);
			        mProgressDialog2.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
			        mProgressDialog2.setMessage("Loading......");                       
			    	mProgressDialog2.setCancelable(true);
				}
				
				if(mProgressDialog2!=null)
					mProgressDialog2.show();
				
				
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
				
				
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!Cancle)
				{
					Toast.makeText(ContentActivity.this, desc, 800).show();

				
				
				if(mProgressDialog2!=null)
					mProgressDialog2.hide();
				}
			}
		}
		
		
		@SuppressWarnings("unused")
		public void ShowDialog_Note()
		{
			
			final Dialog dialog = new Dialog(ContentActivity.this,android.R.style.Theme_Translucent_NoTitleBar);
			//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
			//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
			dialog.setContentView(R.layout.dialog_note);
	        dialog.setCancelable(true);
	        dialog.show();
	       
	        final EditText edt=(EditText)dialog.findViewById(R.id.editText_note);
	        final EditText edt2=(EditText)dialog.findViewById(R.id.editText_title);
	        edt.setText(Text_Note);
	        edt2.setText(editText_title);
	        
	       
	        
	        dialog.findViewById(R.id.lay_save).setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) { 
					
					
					Text_Note=edt.getText().toString();
					
					
					editText_title=edt2.getText().toString();
					
					if(new ConnectInternet(ContentActivity.this).checkInternetConnection())
					new Load_AddNote().execute();
				}
			});
	        
	        
		}
		public void ShowDialog_Note_Read()
		{
			
			final Dialog dialog = new Dialog(ContentActivity.this,android.R.style.Theme_Translucent_NoTitleBar);
			//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
			//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
			dialog.setContentView(R.layout.dialog_note_read);
	        dialog.setCancelable(true);
	        dialog.show();
	       
	       TextView txt_note_title=(TextView)dialog.findViewById(R.id.txt_note_title);
	       txt_note_title.setText(editText_title);
	       
	       TextView txt_note_data=(TextView)dialog.findViewById(R.id.txt_note_data);
	       txt_note_data.setText(Text_Note);
	        
	        
		}
		
		
		private String Text_Note="",editText_title="";
		
		
		class Load_AddNote extends AsyncTask<Object, Integer, Object> {

			  

			private ProgressDialog mProgressDialog3;
			private String title,content,images,date,link,result,desc;
			private boolean Cancle=false;
			
			  @Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				  Cancle=true;
				super.onCancelled();
			}
			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					 ArrayList<String> arrayList_parametor=new ArrayList<String>();
					 ArrayList<String> arrayList_value=new ArrayList<String>();
					
					 arrayList_parametor.add("pageid");
					 arrayList_value.add(Control.page_id);
						
					 arrayList_parametor.add("username");
					 arrayList_value.add(Control.UserName);
			
					 arrayList_parametor.add("title");
					 arrayList_value.add(editText_title);
			
					 
					 
					 arrayList_parametor.add("notes");
					 arrayList_value.add(Text_Note);
			
					 
					 Log.e("TG","Save Note:"+Control.page_id+":"+Control.UserName+":"+Text_Note);
					 
					 
					 SendToBD sd=new SendToBD(ContentActivity.this);
					 String respone=sd.send(
								Control.user, 
								Control.pass, 
								Control.getAPI_SaveNote(),
								arrayList_parametor,
								arrayList_value);
						
						JSONObject jsonObj;
						jsonObj = new JSONObject(respone);
						
						
						Log.e("tg","desc="+jsonObj.getString("desc"));
					
						desc=jsonObj.getString("desc");
						
						
						
						
					
					 
					} catch (JSONException e) {
						
						e.printStackTrace();
					
					}
				return null;
			}
					

			@Override
			protected void onPreExecute() {

				 //=====================ProgressDialog==========================
				if(mProgressDialog3==null)
				{
			        mProgressDialog3 = new ProgressDialog(ContentActivity.this);
			        mProgressDialog3.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
			        mProgressDialog3.setMessage("Save Note....");                       
			    	mProgressDialog3.setCancelable(true);
				}
				
				if(mProgressDialog3!=null)
					mProgressDialog3.show();
				
				
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
				
				
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!Cancle)
				{
					Toast.makeText(ContentActivity.this, desc, 800).show();

				}
				
			if(mProgressDialog3!=null)
				mProgressDialog3.hide();
			}

		}
		
		class Load_DATANote extends AsyncTask<Object, Integer, Object> {

			  

			private ProgressDialog mProgressDialog3;
			private String title,content,images,date,link,result,desc;
			private boolean Cancle=false;
			
			  @Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				  Cancle=true;
				super.onCancelled();
			}
			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					 ArrayList<String> arrayList_parametor=new ArrayList<String>();
					 ArrayList<String> arrayList_value=new ArrayList<String>();
					
					 arrayList_parametor.add("pageid");
					 arrayList_value.add(Control.page_id);
						
					 arrayList_parametor.add("username");
					 arrayList_value.add(Control.UserName);
			
					
					 
					 SendToBD sd=new SendToBD(ContentActivity.this);
					 String respone=sd.send(
								Control.user, 
								Control.pass, 
								Control.getAPI_LoadNotePage(),
								arrayList_parametor,
								arrayList_value);
						
						JSONObject jsonObj;
						jsonObj = new JSONObject(respone);
						
						JSONArray array_note=jsonObj.getJSONArray("notes");
						
						 JSONObject jsonObj_data=array_note.getJSONObject(0);
						
						 editText_title=jsonObj_data.getString("title");
						 Text_Note=jsonObj_data.getString("note");
					
					 
					} catch (JSONException e) {
						
						e.printStackTrace();
					
					}
				return null;
			}
					

			@Override
			protected void onPreExecute() {

				 //=====================ProgressDialog==========================
				if(mProgressDialog3==null)
				{
			        mProgressDialog3 = new ProgressDialog(ContentActivity.this);
			        mProgressDialog3.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
			        mProgressDialog3.setMessage("Save Note....");                       
			    	mProgressDialog3.setCancelable(true);
				}
				
				if(mProgressDialog3!=null)
					mProgressDialog3.show();
				
				
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
				
				
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!Cancle)
				{
					
					if(!Control.Call_From_Note)
					ShowDialog_Note();
					else
						ShowDialog_Note_Read();
					
					Toast.makeText(ContentActivity.this, desc, 800).show();

				}
				
			if(mProgressDialog3!=null)
				mProgressDialog3.hide();
			}

		}
		
		
		
		class Load_AddToHistory extends AsyncTask<Object, Integer, Object> {

		    private ProgressDialog mProgressDialog;
			private String title,content,images,date,link,result,desc;
			private boolean Cancle=false;
				
				
				
				
				  @Override
				protected void onCancelled() {
					// TODO Auto-generated method stub
					  Cancle=true;
					super.onCancelled();
				}
			
			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					
					JSONObject jsonObj=null;
					jsonObj = new JSONObject(HttpGetJson.GetJson(Control.getAPI_AddToHistory(Control.UserName.replace(" ", "%20"),Control.page_id),Control.user,Control.pass));
					
					desc="AddToHistory:"+jsonObj.getString("desc");
			  
			    
			    
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
					 
				return null;
			}

			@Override
			protected void onPreExecute() {

			
				
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
				
				
			}

			@Override
			protected void onPostExecute(Object result) {
				Toast.makeText(ContentActivity.this, desc, 800).show();

				if(!Cancle)
				{
					
	
				}
			

			}
		}
		
		
		
		
		@Override
		public void onStop() {
			// TODO Auto-generated method stub
			Log.e("TG", "onStop()");
			//Ask_Loaddata.cancel(true);
		
			EasyTracker.getInstance().activityStop(this); // Add this method.
			
			Control.Call_From_Note=false;
			super.onStop();
			
		}
		
		

		//Data in blockCard
		
		TextView txt_title1,txt_title2,txt_title3,txt_title4,txt_title5,txt_title6,txt_title7,txt_title8,txt_title9,txt_title10,txt_title11,txt_title12,txt_title13,txt_title14;
		LinearLayout Lay_subCard1,Lay_subCard2,Lay_subCard3,Lay_subCard4;
		FrameLayout lay_viewmore;
		private TextView[] arr_BlockTitle={txt_title1,txt_title2,txt_title3,txt_title4,txt_title5,txt_title6,txt_title7,txt_title8,txt_title9,txt_title10,txt_title11,txt_title12,txt_title13,txt_title14};
		private LinearLayout[] arr_laycard={Lay_subCard1,Lay_subCard2,Lay_subCard3,Lay_subCard4};
		
		private void AddBlockCard(String Title,String id)
		{
			 ArrayList<String> List_Block_Title = new ArrayList<String>();

			
			
			LayoutInflater factory = LayoutInflater.from(ContentActivity.this);
			View myView = factory.inflate(R.layout.item_card, null);
			final TextView text=(TextView)myView.findViewById(R.id.txt_card);
			final TextView txt_id=(TextView)myView.findViewById(R.id.txt_id);
			
			//Init Text_Title
			arr_BlockTitle[0]=(TextView)myView.findViewById(R.id.txt_title1);
			arr_BlockTitle[1]=(TextView)myView.findViewById(R.id.txt_title2);
			arr_BlockTitle[2]=(TextView)myView.findViewById(R.id.txt_title3);
			arr_BlockTitle[3]=(TextView)myView.findViewById(R.id.txt_title4);
			arr_BlockTitle[4]=(TextView)myView.findViewById(R.id.txt_title5);
			arr_BlockTitle[5]=(TextView)myView.findViewById(R.id.txt_title6);
			arr_BlockTitle[6]=(TextView)myView.findViewById(R.id.txt_title7);
			arr_BlockTitle[7]=(TextView)myView.findViewById(R.id.txt_title8);
			arr_BlockTitle[8]=(TextView)myView.findViewById(R.id.txt_title9);
			arr_BlockTitle[9]=(TextView)myView.findViewById(R.id.txt_title10);
			arr_BlockTitle[10]=(TextView)myView.findViewById(R.id.txt_title11);
			arr_BlockTitle[11]=(TextView)myView.findViewById(R.id.txt_title12);
			arr_BlockTitle[12]=(TextView)myView.findViewById(R.id.txt_title13);
			arr_BlockTitle[13]=(TextView)myView.findViewById(R.id.txt_title14);

			arr_laycard[0]=(LinearLayout)myView.findViewById(R.id.Lay_subCard1);
			arr_laycard[1]=(LinearLayout)myView.findViewById(R.id.Lay_subCard2);
			arr_laycard[2]=(LinearLayout)myView.findViewById(R.id.Lay_subCard3);
			arr_laycard[3]=(LinearLayout)myView.findViewById(R.id.Lay_subCard4);

			lay_viewmore=(FrameLayout)myView.findViewById(R.id.lay_viewmore);
			
			
			txt_id.setText(Html.fromHtml(id));
			int count_card=0;
			for (int i = 0; i < MyArrList_card.size(); i++) {
				if(MyArrList_card.get(i).get("block_id").toString().equals(id)&&MyArrList_card.get(i).get("block_title").toString().equals(Title))
				{
					List_Block_Title.add(MyArrList_card.get(i).get("name").toString());
					count_card++;
				}
				
				
			}
			
			Log.e("card","count_card:"+count_card+"");
			
			//=======SetData to Block
			for (int i = 0; i < List_Block_Title.size(); i++) 
			{
				if(i<4)
				{
					arr_BlockTitle[i].setText(List_Block_Title.get(i).toString());
				}
				else
					if(i<14)
					{
						arr_BlockTitle[i].setText(List_Block_Title.get(i).toString());

						
					}
				
			}
			
			//Chk GONE View
			if(count_card<=4)
				lay_viewmore.setVisibility(View.GONE);
				//hide view more
				
			
			for (int i = 0; i < arr_BlockTitle.length; i++) 
			{
				if(i>=count_card&&i<=3)
				{
					arr_laycard[i].setVisibility(View.GONE);
				}
				
				
				if(i>=count_card&&i>3)
				{
					arr_BlockTitle[i].setVisibility(View.GONE);
				}
				
				
			}
			
			
			
			
			
			///========Onclick
			txt_id.setOnClickListener(new OnClickListener() { public void onClick(View v)
			    {
			    	
			       Log.e("TG",text.getText().toString());
			       Control.block_id=txt_id.getText().toString();
			       //ContentActivity.this.finish();
			       startActivity(new Intent(ContentActivity.this,CardActivity.class));
			       ContentActivity.this.overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
			       Toast.makeText(ContentActivity.this, txt_id.getText().toString(), 800).show();
			       
			       
			       
			    } 
			});
			lay_viewmore.setOnClickListener(new OnClickListener() { public void onClick(View v)
		    {
		    	
			       Log.e("TG",text.getText().toString());
			       Control.block_id=txt_id.getText().toString();
			       //ContentActivity.this.finish();
			       startActivity(new Intent(ContentActivity.this,CardActivity.class));
			       ContentActivity.this.overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
			       Toast.makeText(ContentActivity.this, txt_id.getText().toString(), 800).show();
			       
			       
			       
			    } 
			});
			
			
			
			
			
			
			
			//=====Add to view
		    text.setText(Html.fromHtml(Title));
			ViewGroup layout = (ViewGroup)findViewById(R.id.LayCard);
			myView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			layout.addView(myView);
		
		}
		
		
		private void AddWebView(String Data)
		{
			LayoutInflater factory = LayoutInflater.from(ContentActivity.this);
			View myView = factory.inflate(R.layout.item_content, null);
			
			WebView wv=(WebView)myView.findViewById(R.id.webView1);
			wv.loadDataWithBaseURL(null, Data, "text/html", "UTF-8", null);
			wv.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
			wv.setWebViewClient(new WebViewClient(){

			    @Override
			    public boolean shouldOverrideUrlLoading(WebView view, String url){
			      
			    	Log.e("tglobe","url:"+url);
			    	
			    	
			    	//ค้นหา"/"
			    	url.lastIndexOf("/");
			        String NewId=url.substring(url.lastIndexOf("/")+1, url.length());
			        Log.e("tglobe","NewId:"+NewId);
			       
						Control.page_id=NewId;
						SliderMenuLeft.Mainmenu_List_Menu_Title.add(url);
						
						if(new ConnectInternet(THIS).checkInternetConnection())
						{
							try {txt_title.setText(url);} catch (Exception e) {
								// TODO: handle exception
							}
							
							
							mSlideMenu.close(true);
							new LoadData_MainMenu().execute();
						}
					
			      
			      return true;
			    }
			});
			
			ViewGroup layout = (ViewGroup)findViewById(R.id.LayCard);
			myView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
			layout.addView(myView);
		}
		
		
		
		
		
			private TextView txt_title;
		public static ArrayList<Integer> index_card = new ArrayList<Integer>();	
		class LoadData2 extends AsyncTask<Object, Integer, Object> {

			
			private boolean DATA_Error=false;
			
			
			private String URL_CoverPage="";
			private Boolean onCancelled=false;
			
			@Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
			Log.e("globe", "onCancelled()");
			onCancelled=true;
				super.onCancelled();
			}

			
			
			
			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				
				try {
					
					JSONObject jsonObj=null;
					
					if(Control.Data_ContentAPI.equals(""))
					{
						jsonObj = new JSONObject(HttpGetJson.GetJson(Control.getAPI_Content(Control.page_id),Control.user,Control.pass));
						Control.Data_ContentAPI=HttpGetJson.GetJson(Control.getAPI_Content(Control.page_id),Control.user,Control.pass);
					}
					else
						jsonObj = new JSONObject(Control.Data_ContentAPI);
					
					
					//Log.e("tglobe","Control.Data_ContentAPI="+Control.Data_ContentAPI);
				
					
					try {URL_CoverPage=jsonObj.getString("coverpage").toString();}catch (JSONException e) { Log.e("TG2", "URL_CoverPage Empty:"+URL_CoverPage); URL_CoverPage="http://";e.printStackTrace();}
					
					Log.e("TG2", "URL_CoverPage:"+URL_CoverPage);
					

					JSONArray jsonarray_data=jsonObj.getJSONArray("data");
					
					for (int i = 0; i <jsonarray_data.length(); i++)
					{
						map_content = new HashMap<String, Object>();
						JSONObject jsonObj_data=jsonarray_data.getJSONObject(i);

						//try { Log.e("tglobe","type="+jsonObj_data.getString("type").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
							
						if(jsonObj_data.getString("type").toString().equals("content")||jsonObj_data.getString("type").toString().equals("richard"))
						{
								//try { Log.e("tglobe","block_title="+jsonObj_data2.getString("block_title").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								try {map_content.put("block_title", jsonObj_data.getString("block_title").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								try {map_content.put("block_id", jsonObj_data.getString("block_id").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								try {map_content.put("block_title", jsonObj_data.getString("block_title").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								
								
								//try {URL_CoverPage=jsonObj_data.getString("coverpage").toString();}catch (JSONException e) {URL_CoverPage="http://";e.printStackTrace();}
								
								MyArrList_content.add(map_content);
								index_card.add(9999);
						}
						else
						{
							try {
								
							
							   //Log.e("tglobe","index_card="+i);
							   index_card.add(i);
								//try { Log.e("tglobe","block_title="+jsonObj_data.getString("block_title").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								try {map_content.put("block_title", jsonObj_data.getString("block_title").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}
								try {map_content.put("block_id", jsonObj_data.getString("block_id").toString());} catch (JSONException e) {Toast.makeText(ContentActivity.this,"Error="+e.toString(), 900).show();}

								
								try {
									JSONArray jsonarray_card=jsonObj_data.getJSONArray("card");
								
									for (int i2 = 0; i2 <jsonarray_card.length(); i2++)
									{
										map_card = new HashMap<String, Object>();
										JSONObject jsonObj_card=jsonarray_card.getJSONObject(i2);								
										
										try { Log.e("card","--------------["+i2+"] card_id="+jsonObj_card.getString("card_id").toString()+"  Bolckk_id:"+jsonObj_data.getString("block_id").toString());} catch (JSONException e) {e.printStackTrace();}
										
										//try { Log.e("card","block_id="+jsonObj_data.getString("block_id").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","name="+jsonObj_card.getString("name").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","name2="+jsonObj_card.getString("name2").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","cardtype="+jsonObj_card.getString("cardtype").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","sponsortype="+jsonObj_card.getString("sponsortype").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","tel="+jsonObj_card.getString("tel").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","web="+jsonObj_card.getString("web").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","img="+jsonObj_card.getString("img").toString());} catch (JSONException e) {e.printStackTrace();}
//										try { Log.e("card","card_desc="+jsonObj_card.getString("card_desc").toString());} catch (JSONException e) {e.printStackTrace();}

//						                   
//						                   "latitude": "17.440534",
//						                   "longitude": "99.786560 75 ",
//						                  
										try {map_card.put("block_id",jsonObj_data.getString("block_id").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("block_title",jsonObj_data.getString("block_title").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("name",jsonObj_card.getString("name").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("name2",jsonObj_card.getString("name2").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("cardtype",jsonObj_card.getString("cardtype").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("sponsortype",jsonObj_card.getString("sponsortype").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("tel",jsonObj_card.getString("tel").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("web",jsonObj_card.getString("web").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("img",jsonObj_card.getString("img").toString());} catch (JSONException e) {e.printStackTrace();}
										try {map_card.put("card_desc",jsonObj_card.getString("card_desc").toString());} catch (JSONException e) {e.printStackTrace();}

										
										
						                MyArrList_card.add(map_card);
						                   
									}
									
									
									
								} catch (Exception e) {Log.e("card","==No card==");};
								
								
								
								MyArrList_content.add(map_content);
								
							} catch (Exception e) {
								Log.e("tglobe", e.toString());
							}
						}

					}

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						onCancelled=true;
					}
					
				
				
				return null;
			}

			@Override
			protected void onPreExecute() {

				Control.Data_ContentAPI="";
				Log.e("TG","LOad Data2 Control.page_id:"+Control.page_id);
				MyArrList_content.clear();
				ViewGroup layout = (ViewGroup)findViewById(R.id.LayCard);
				layout.removeAllViews();
				progressBar1.setVisibility(View.VISIBLE);
				Log.e("TG","Control.page_id:"+Control.page_id);

				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

			
				Log.e("ASK", "progress:"+progress[0]);
				
			}

			@Override
			protected void onPostExecute(Object result) {
				
				
				//Picasso.with(ContentActivity.this).load(URL_CoverPage).into(imageView);

			
				
				
			if(!onCancelled)
			{
				//if(URL_CoverPage.length()>0)
				Picasso.with(ContentActivity.this).load(URL_CoverPage).into(img_title);
				
				
				try{
					
					
					
					int i=0;
					while(i<MyArrList_content.size())
					{
						Log.e("tglobe","MyArrList_content="+i);
						if(i!=index_card.get(i))
						{
							AddWebView(MyArrList_content.get(i).get("block_title").toString());	
						}
						else	
						{
							
							AddBlockCard(MyArrList_content.get(i).get("block_title").toString(),MyArrList_content.get(i).get("block_id").toString());	
						}
						i++;
					}
					
						
				
					
					} catch (Exception e) {
						// TODO Auto-generated catch block
						Toast.makeText(ContentActivity.this,e.toString(), 900).show();
						e.printStackTrace();
					}
					
				
				
				}
			progressBar1.setVisibility(View.INVISIBLE);
			
			}
			

		}
		
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
			if(v.getId()==R.id.img_profile)
			{
				mSlideMenu.open_R(true, true);

			}
			else
			if(v.getId()==R.id.img_mainmenu)
			{
				mSlideMenu.open_L(true, true);

			}
			
			
			
			
			
			//======Profile
//			//================Menu==============
					if(v.getId()==R.id.img_profile_menu1)
					{
						startActivity(new Intent(ContentActivity.this,MyHistoryActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu2)
					{
						startActivity(new Intent(ContentActivity.this,MyBookmarkActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu3)
					{
						startActivity(new Intent(ContentActivity.this,MyNoteActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu4)
					{
						//startActivity(new Intent(MainActivity.this,MyCompareActivity.class));
						startActivity(new Intent(ContentActivity.this,CompareActivity.class));
						
					}
					if(v.getId()==R.id.img_profile_menu5)
					{
						startActivity(new Intent(ContentActivity.this,MyNoteActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu6)
					{
						startActivity(new Intent(ContentActivity.this,TglobeAppActivity.class));
					}
					
					if(v.getId()==R.id.img_profile_menu7)
					{
						startActivity(new Intent(ContentActivity.this,MyDiscountActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu8)
					{
						startActivity(new Intent(ContentActivity.this,MySettingActivity.class));
					}
					if(v.getId()==R.id.img_profile_menu9)
					{
						Control.Loginstatus=false;
						Control.UserName="";
						Control.UserPassword="";
						SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	

						Editor editor = sharedpreferences.edit();
						editor.putString("Username", Control.UserName);
						editor.putString("Password", Control.UserPassword);
						
						
						Log.e("tglobe","======Logout=======");

						Log.e("tglobe",sharedpreferences.getString("Username", ""));
						Log.e("tglobe",sharedpreferences.getString("Password", ""));
						ContentActivity.this.finish();
						startActivity(new Intent(ContentActivity.this,LoginActivity.class));
					}

					
					
					if(v.getId()==R.id.img_user)
					{

						startActivity(new Intent(ContentActivity.this,MyprofileActivity.class));
					}
					
			//===============
			
			
			
			
		}


		
		
		//================SetProfileMenu====================
		
		
		
		public void SetMainMenu()
		{
		
			

			
			
			Mainmenu_lstView = (ListView)THIS.findViewById(R.id.list_view);
			Mainmenu_lstView_params = Mainmenu_lstView.getLayoutParams();
			txt_title.setText(SliderMenuLeft.Content_title);

			THIS.setProgressBarIndeterminateVisibility(true);
			Mainmenu_lstView.setOnItemClickListener(new OnItemClickListener() {

				
				
				@Override
				public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {
					// TODO Auto-generated method stub
					

					if(Mainmenu_MyArrList.get(position).get("Data").toString().equals("")||
							Mainmenu_MyArrList.get(position).get("Data").toString().equals("[]")	)
					{
						Control.page_id=Mainmenu_MyArrList.get(position).get("Id").toString();
						SliderMenuLeft.Mainmenu_List_Menu_Title.add(Mainmenu_MyArrList.get(position).get("Title").toString());
						
						if(new ConnectInternet(THIS).checkInternetConnection())
						{
							try {txt_title.setText(Mainmenu_MyArrList.get(position).get("Title").toString());} catch (Exception e) {
								// TODO: handle exception
							}
							
							
							mSlideMenu.close(true);
							new LoadData_MainMenu().execute();
						}
					}
					else
					{
						
						SliderMenuLeft.Mainmenu_List_Menu_Title.add(Mainmenu_MyArrList.get(position).get("Title").toString());
						Add_ChildToList(Mainmenu_MyArrList.get(position).get("Data").toString(),true);
					}
					
					
					if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
						 THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
						else
							THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
					
					Log.e("Tglobe", "Control.Mainmenu_List_DATA_History.size():"+SliderMenuLeft.Mainmenu_List_DATA_History.size());

				}

			});
			 //=====================ProgressDialog==========================
	        mProgressDialog = new ProgressDialog(THIS);
	        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
	        mProgressDialog.setMessage("Loading......");                       
	        mProgressDialog.setCancelable(true);  

	        
	    
	       
	       
	       
	        Mainmenu_txt_title_menu=(TextView)THIS.findViewById(R.id.txt_title_menu);
	       // 
	        
	        
	        
	        
	        if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
	        	THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
	        else
	        	THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
	        
	        
	        THIS.findViewById(R.id.img_back_list).setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					

					
					if(SliderMenuLeft.Mainmenu_List_DATA_History.size()>1)
					{
						THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
						Log.e("TG", "size : "+SliderMenuLeft.Mainmenu_List_DATA_History.size());
						SliderMenuLeft.Mainmenu_List_DATA_History.remove(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1);


						
						
						
						SliderMenuLeft.Mainmenu_List_Menu_Title.remove(SliderMenuLeft.Mainmenu_List_Menu_Title.size()-1);
						Log.e("TG", "Type : "+SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Type);
						
						if(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Type.equals("child"))
							{
							
							Add_ChildToList(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Data,false);
							}
						else
						{
							
							Add_MainMenuToList(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Data,false);
						}
						

					}
					
					if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
						THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
					
					
					Log.e("TG", "size : "+SliderMenuLeft.Mainmenu_List_Menu_Title.size());
					Log.e("Tglobe", "Control.Mainmenu_List_DATA_History.size():"+SliderMenuLeft.Mainmenu_List_DATA_History.size());

				}
			});
	        
	        
	        
	        
	        
	        
	        
	      Mainmenu_MyArrList = new ArrayList<HashMap<String, Object>>();
			
			if(new ConnectInternet(THIS).checkInternetConnection())
			{
				
			
				
				
				Log.e("tglobe", "===========LoadData_MainMenu().execute()=========");
				   new LoadData_MainMenu().execute();
				
				//new LoadData_information().execute();
			}
			
			
		}
		
		private void SetViewProfile() {
			// TODO Auto-generated method stub
			
			
			Laylogin=(FrameLayout)findViewById(R.id.Laylogin);
			if(!Control.Loginstatus)
				Laylogin.setVisibility(View.VISIBLE);
			
			
			//=======menu
			img_profile_menu1=(ImageView)findViewById(R.id.img_profile_menu1);
			img_profile_menu2=(ImageView)findViewById(R.id.img_profile_menu2);
			img_profile_menu3=(ImageView)findViewById(R.id.img_profile_menu3);
			img_profile_menu4=(ImageView)findViewById(R.id.img_profile_menu4);
			img_profile_menu5=(ImageView)findViewById(R.id.img_profile_menu5);
			img_profile_menu6=(ImageView)findViewById(R.id.img_profile_menu6);
			img_profile_menu7=(ImageView)findViewById(R.id.img_profile_menu7);
			img_profile_menu8=(ImageView)findViewById(R.id.img_profile_menu8);
			img_profile_menu9=(ImageView)findViewById(R.id.img_profile_menu9);
			
			

			TextView txt_username=(TextView) findViewById(R.id.txt_username);
			txt_username.setText(Control.UserName);
			
			
			img_user=(ImageView)findViewById(R.id.img_user);
			img_user.setOnClickListener(this);
			 
			try {
				
				
				
				Log.e("Picasso", "=========Picasso() ==========");
				
				if(Control.Img_profile.equals(""))
				{
					img_user.setImageResource(R.drawable.btn_menu_top_righ);

				}
				else
				{
					Bitmap myBitmap = BitmapFactory.decodeFile(Control.Img_profile_Path);
					img_user.setImageBitmap(myBitmap);
				}
				
				
				
				} catch (Exception e) {
					img_user.setImageResource(R.drawable.btn_menu_top_righ);
				}
			
			
			img_profile_menu1.setOnClickListener(this);
			img_profile_menu2.setOnClickListener(this);
			img_profile_menu3.setOnClickListener(this);
			img_profile_menu4.setOnClickListener(this);
			img_profile_menu5.setOnClickListener(this);
			img_profile_menu6.setOnClickListener(this);
			img_profile_menu7.setOnClickListener(this);
			img_profile_menu8.setOnClickListener(this);
			img_profile_menu9.setOnClickListener(this);

			
			
			//=========Login
			txt_next=(LinearLayout)findViewById(R.id.txt_next);
			txt_next.setOnClickListener(this);
			
			txt_register=(LinearLayout)findViewById(R.id.txt_register);
			txt_register.setOnClickListener(this);
			
			
			ImageView img_tglobe_login=(ImageView)findViewById(R.id.img_tglobe_login);
			img_tglobe_login.setOnClickListener(this);
			
			ImageView img_facebook =(ImageView)findViewById(R.id.img_facebook);
			img_facebook.setOnClickListener(this);
			
			
			
		}

		
		
		
		
		
		class ADDData_MainMenu_ extends AsyncTask<Object, Integer, Object> {
			
			
			
			

			private boolean ONcancle=false;
			

			@Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				ONcancle=true;
				super.onCancelled();
			}

			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					ArrayList<String> arrayList_parametor = new ArrayList<String>();
					ArrayList<String> arrayList_value = new ArrayList<String>();

					arrayList_parametor.add("id");
					arrayList_value.add(Control.page_id);

					SendToBD sd = new SendToBD(THIS);
					SliderMenuLeft.Mainmenu_Data_Dafalt = sd.send("", "", Control.API_main_menu,arrayList_parametor, arrayList_value);
					//Log.e("evt", "API_main_menu=" + SliderMenuLeft.Mainmenu_Data_Dafalt + "");

					JSONObject jsonObj = null;
					jsonObj = new JSONObject(SliderMenuLeft.Mainmenu_Data_Dafalt);
					JSONArray jsonarray_information = jsonObj.getJSONArray("information");

					// ===========Add to History
					MenuData menudata = new MenuData();
					menudata.Data = jsonObj.getJSONArray("information").toString();
					menudata.Type = "main";
					
					
					
					SliderMenuLeft.Mainmenu_List_DATA_History.add(menudata);

					for (int i = 0; i < jsonarray_information.length(); i++) {

						JSONObject jsonObj_information = jsonarray_information
								.getJSONObject(i);

						
						Mainmenu_map = new HashMap<String, Object>();
						Mainmenu_map.put("Title", jsonObj_information.getString("main_menu"));
						Mainmenu_map.put("Id", jsonObj_information.getString("page_id"));
						Mainmenu_map.put("Stuck", "main_menu");

						try {
							JSONArray jsonarray_main_menu_child = jsonObj_information
									.getJSONArray("main_menu_child");
							if (jsonarray_main_menu_child.length() > 0)
								Mainmenu_map.put("Type", "main");
							else
								Mainmenu_map.put("Type", "child");

							Mainmenu_map.put("Data", jsonarray_main_menu_child.toString());

						} catch (Exception ex) {
							Mainmenu_map.put("Type", "child");
							Mainmenu_map.put("Data", "");
						}

						Mainmenu_MyArrList.add(Mainmenu_map);
					
					                // This code will always run on the UI thread, therefore is safe to modify UI elements.
						THIS.runOnUiThread(new Runnable() {
							@Override
							public void run() {
						          Mainmenu_adapter.notifyDataSetChanged();
							}
						    });
					      
						

					}

				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Log.e("TG", "JsonError:"+e.toString());
				}

				return null;
			}

			@Override
			protected void onPreExecute() {
				
				//adapter=null;
				//mSlideMenu.close(true);
				Mainmenu_MyArrList.clear();
			    
				if (Mainmenu_adapter == null) {
					Mainmenu_adapter = new MainmenuListAdapter(THIS,Mainmenu_MyArrList);
					Mainmenu_lstView.setAdapter(Mainmenu_adapter);
				}
				
				
				// =====================ProgressDialog==========================
				mProgressDialog = new ProgressDialog(THIS);
				mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
				mProgressDialog.setMessage("Loading......");
				mProgressDialog.setCancelable(true);

				if (mProgressDialog != null)
				mProgressDialog.show();

				
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!ONcancle)
		    	{
				
				if (mProgressDialog != null)
					mProgressDialog.hide();
				//SetLayOut
		    	
					//Mainmenu_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());
				ResizeWidthAnimation anim = new ResizeWidthAnimation(Mainmenu_lstView,Mainmenu_lstView.getWidth() ,(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics()));
			    anim.setDuration(300);
			    Mainmenu_lstView.startAnimation(anim);
					 
					if(new ConnectInternet(THIS).checkInternetConnection())
					new LoadData2().execute();
							 
							 
					 
					 Mainmenu_txt_title_menu.setText(SliderMenuLeft.Mainmenu_List_Menu_Title.get(SliderMenuLeft.Mainmenu_List_Menu_Title.size()-1));
		    	
					  if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
						  THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
				        else
				        	THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
				        
					   
					 
		    	
		    	}  
		    	
		    	
			}
		}

		class LoadData_MainMenu extends AsyncTask<Object, Integer, Object> {
			
			
			
			

			private boolean ONcancle=false;
			

			@Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				ONcancle=true;
				super.onCancelled();
			}

			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				try {
					ArrayList<String> arrayList_parametor = new ArrayList<String>();
					ArrayList<String> arrayList_value = new ArrayList<String>();

					arrayList_parametor.add("id");
					arrayList_value.add(Control.page_id);

					SendToBD sd = new SendToBD(THIS);
					SliderMenuLeft.Mainmenu_Data_Dafalt = sd.send("", "", Control.API_main_menu,arrayList_parametor, arrayList_value);
				//	Log.e("evt", "API_main_menu=" + SliderMenuLeft.Mainmenu_Data_Dafalt + "");

					JSONObject jsonObj = null;
					jsonObj = new JSONObject(SliderMenuLeft.Mainmenu_Data_Dafalt);
					JSONArray jsonarray_information = jsonObj.getJSONArray("information");

					// ===========Add to History
					MenuData menudata = new MenuData();
					menudata.Data = jsonObj.getJSONArray("information").toString();
					menudata.Type = "main";
					
					
					
					SliderMenuLeft.Mainmenu_List_DATA_History.add(menudata);

					for (int i = 0; i < jsonarray_information.length(); i++) {

						JSONObject jsonObj_information = jsonarray_information
								.getJSONObject(i);

						
						Mainmenu_map = new HashMap<String, Object>();
						Mainmenu_map.put("Title", jsonObj_information.getString("main_menu"));
						Mainmenu_map.put("Id", jsonObj_information.getString("page_id"));
						Mainmenu_map.put("Stuck", "main_menu");

						try {
							JSONArray jsonarray_main_menu_child = jsonObj_information
									.getJSONArray("main_menu_child");
							if (jsonarray_main_menu_child.length() > 0)
								Mainmenu_map.put("Type", "main");
							else
								Mainmenu_map.put("Type", "child");

							Mainmenu_map.put("Data", jsonarray_main_menu_child.toString());

						} catch (Exception ex) {
							Mainmenu_map.put("Type", "child");
							Mainmenu_map.put("Data", "");
						}

						Mainmenu_MyArrList.add(Mainmenu_map);
					
					                // This code will always run on the UI thread, therefore is safe to modify UI elements.
						THIS.runOnUiThread(new Runnable() {
							@Override
							public void run() {
						          Mainmenu_adapter.notifyDataSetChanged();
							}
						    });
					      
						

					}

				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Log.e("TG", "JsonError:"+e.toString());
				}

				return null;
			}

			@Override
			protected void onPreExecute() {
				
				//adapter=null;
				//mSlideMenu.close(true);
				try {
					
				
				Mainmenu_MyArrList.clear();
			    
				if (Mainmenu_adapter == null) {
					Mainmenu_adapter = new MainmenuListAdapter(THIS, Mainmenu_MyArrList);
					Mainmenu_lstView.setAdapter(Mainmenu_adapter);
				}
				
				
				// =====================ProgressDialog==========================
				mProgressDialog = new ProgressDialog(THIS);
				mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
				mProgressDialog.setMessage("Loading......");
				mProgressDialog.setCancelable(true);

				if (mProgressDialog != null)
				mProgressDialog.show();

				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

				Log.e("star", "progressupdate");
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!ONcancle)
		    	{
				
				if (mProgressDialog != null)
					mProgressDialog.hide();
				//SetLayOut
		    	
					//Mainmenu_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());
				ResizeWidthAnimation anim = new ResizeWidthAnimation(Mainmenu_lstView,Mainmenu_lstView.getWidth() ,(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics()));
			    anim.setDuration(300);
			    Mainmenu_lstView.startAnimation(anim);	
				
				
					if(new ConnectInternet(THIS).checkInternetConnection())
					{
						
						new LoadData2().execute();
					}	 
							 
					 
					
					
					try {
						Mainmenu_txt_title_menu.setText(SliderMenuLeft.Mainmenu_List_Menu_Title.get(SliderMenuLeft.Mainmenu_List_Menu_Title.size()-1));
					} catch (Exception e) {
						e.printStackTrace();
					} 
		    	
					  if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
						  THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
				        else
				        	THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
				        
					   
					 
		    	
		    	}  
		    	
		    	
			}
		}
		private void Add_ChildToList(String Data,Boolean AddNewData) {
			//Log.e("TG", "Add_Child_To_List=:" + Data);
			
			if(AddNewData){
			MenuData menudata = new MenuData();
			menudata.Data = Data;
			menudata.Type = "child";
			SliderMenuLeft.Mainmenu_List_DATA_History.add(menudata);
			}
		

			// =================================
			Mainmenu_adapter = null;
			Mainmenu_MyArrList.clear();
			if (Mainmenu_adapter == null) {
				Mainmenu_adapter = new MainmenuListAdapter(THIS, Mainmenu_MyArrList);
				Mainmenu_lstView.setAdapter(Mainmenu_adapter);
			}
			try {
				JSONArray JSONarray = new JSONArray(Data);
				for (int i = 0; i < JSONarray.length(); i++) {

					JSONObject jsonObj_information = JSONarray.getJSONObject(i);
					Mainmenu_map = new HashMap<String, Object>();

					String tagName = "name" + (i );
					String tagId = "page_id" + (i);

					
					
					Mainmenu_map.put("Title", jsonObj_information.getString(tagName));
					Mainmenu_map.put("Id", jsonObj_information.getString(tagId));
					Mainmenu_map.put("Stuck", "child");

					try {
						JSONArray jsonarray_child = jsonObj_information
								.getJSONArray("child");
						if (jsonarray_child.length() > 1)
						{
							Mainmenu_map.put("Type", "main");
							Mainmenu_map.put("Data", jsonarray_child.toString());
						}
						else
						{
							Mainmenu_map.put("Type", "child");
							Mainmenu_map.put("Data", "");
						}
						
					} catch (Exception ex) {
						Mainmenu_map.put("Type", "child");
						Mainmenu_map.put("Data", "");
					}
					
					
//					if(JSONarray.length()<1)
//						Mainmenu_map.put("Type", "child");
//						Mainmenu_map.put("Data", "");

					Mainmenu_MyArrList.add(Mainmenu_map);
					THIS.runOnUiThread(new Runnable() {
			            @Override
			            public void run() {
	                // This code will always run on the UI thread, therefore is safe to modify UI elements.
			            	Mainmenu_adapter.notifyDataSetChanged();
			            }
			        });
			    	//Mainmenu_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());
					ResizeWidthAnimation anim = new ResizeWidthAnimation(Mainmenu_lstView,Mainmenu_lstView.getWidth() ,(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics()));
				    anim.setDuration(300);
				    Mainmenu_lstView.startAnimation(anim);
					
					
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Mainmenu_txt_title_menu.setText(SliderMenuLeft.Mainmenu_List_Menu_Title.get(SliderMenuLeft.Mainmenu_List_Menu_Title.size()-1));


		}
		private void Add_MainMenuToList(String Data,Boolean AddNewData) {
			//Log.e("TG", "DATA Add main=:" + Data);

			// =================================
			Mainmenu_adapter = null;
			Mainmenu_MyArrList.clear();
			if (Mainmenu_adapter == null) {
				Mainmenu_adapter = new MainmenuListAdapter(THIS,Mainmenu_MyArrList);
				Mainmenu_lstView.setAdapter(Mainmenu_adapter);
			}
			try {
				JSONArray jsonarray_information = new JSONArray(Data);
				for (int i = 0; i < jsonarray_information.length(); i++) {

					JSONObject jsonObj_information = jsonarray_information
							.getJSONObject(i);

					Mainmenu_map = new HashMap<String, Object>();
					Mainmenu_map.put("Title", jsonObj_information.getString("main_menu"));
					Mainmenu_map.put("Id", jsonObj_information.getString("page_id"));
					Mainmenu_map.put("Stuck", "main_menu");

					try {
						JSONArray jsonarray_main_menu_child = jsonObj_information.getJSONArray("main_menu_child");
						if (jsonarray_main_menu_child.length() > 0)
							Mainmenu_map.put("Type", "main");
						else
							Mainmenu_map.put("Type", "child");

						Mainmenu_map.put("Data", jsonarray_main_menu_child.toString());

					} catch (Exception ex) {
						Mainmenu_map.put("Type", "child");
						Mainmenu_map.put("Data", "");
					}
			    	 
					Mainmenu_MyArrList.add(Mainmenu_map);
					
					THIS.runOnUiThread(new Runnable() {
			            @Override
			            public void run() {
	                // This code will always run on the UI thread, therefore is safe to modify UI elements.
			            	Mainmenu_adapter.notifyDataSetChanged();
			            }
			        });
				//	Mainmenu_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());
					ResizeWidthAnimation anim = new ResizeWidthAnimation(Mainmenu_lstView,Mainmenu_lstView.getWidth() ,(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Mainmenu_MyArrList.size()*50, THIS.getResources().getDisplayMetrics()));
				    anim.setDuration(300);
				    Mainmenu_lstView.startAnimation(anim);
					
					
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			try {
			
			Mainmenu_txt_title_menu.setText(SliderMenuLeft.Mainmenu_List_Menu_Title.get(SliderMenuLeft.Mainmenu_List_Menu_Title.size()-1));
  	
			} catch (Exception e) {
				// TODO: handle exception
			}
			
		}
		public void ReSetMainMenu()
		{
		
			Log.e("Tglobe", "Mainmenu_List_Menu_Title : "+SliderMenuLeft.Mainmenu_List_Menu_Title.size());
			Log.e("Tglobe", "Mainmenu_List_DATA_History:"+SliderMenuLeft.Mainmenu_List_DATA_History.size());
			
			
			if(SliderMenuLeft.Mainmenu_List_DATA_History.size()>1)
			{
				THIS.findViewById(R.id.img_back_list).setVisibility(View.VISIBLE);
				
				if(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Type.equals("child"))
					{
					
					Add_ChildToList(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Data,false);
					}
				else
				{
					
					Add_MainMenuToList(SliderMenuLeft.Mainmenu_List_DATA_History.get(SliderMenuLeft.Mainmenu_List_DATA_History.size()-1).Data,false);
				}
				

			}
			
			if(SliderMenuLeft.Mainmenu_List_DATA_History.size()<=1)
				THIS.findViewById(R.id.img_back_list).setVisibility(View.INVISIBLE);
			
			
			Log.e("Tglobe", "Mainmenu_List_Menu_Title : "+SliderMenuLeft.Mainmenu_List_Menu_Title.size());
			Log.e("Tglobe", "Mainmenu_List_DATA_History:"+SliderMenuLeft.Mainmenu_List_DATA_History.size());
			
			
		}
		
		
		
		
		private ListView information_lstView;
		private informationListAdapter information_adapter;
		public  ArrayList<HashMap<String, Object>> information_MyArrList;
		private HashMap<String, Object> information_map = new HashMap<String, Object>();
		//private ProgressDialog mProgressDialog;
		private TextView information_txt_title_menu;
		private LayoutParams information_lstView_params;
		private void Setinformation()
		{
			
			
		
			
			
			information_lstView = (ListView)THIS.findViewById(R.id.list_view_information);
			information_lstView_params= information_lstView.getLayoutParams();
			THIS.setProgressBarIndeterminateVisibility(true);
			information_lstView.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {
					// TODO Auto-generated method stub
					 if(information_MyArrList.get(position).get("Data").toString().equals("")||
							 information_MyArrList.get(position).get("Data").toString().equals("[]")	)
				        {
						 try{
								
								if(!information_MyArrList.get(position).get("Id").equals(null))
								{
									
									SliderMenuLeft.Mainmenu_List_Menu_Title.add(information_MyArrList.get(position).get("Title").toString());
													
									Control.page_id=information_MyArrList.get(position).get("Id").toString();
									if(new ConnectInternet(THIS).checkInternetConnection())
									new LoadData_MainMenu().execute();
								}
							}
							catch(Exception ex){}
				        }
				        else
				        {
				        	information_List_Menu_Title.add(information_MyArrList.get(position).get("Title").toString());
							Add_information_ChildToList(information_MyArrList.get(position).get("Data").toString(),true);
							
				        }
					 
						Log.e("TG", "information_List_DATA_History size : "+information_List_DATA_History.size());
				
				
						 if(information_List_DATA_History.size()<=1)
							 THIS.findViewById(R.id.img_back_list_information).setVisibility(View.INVISIBLE);
							else
								THIS.findViewById(R.id.img_back_list_information).setVisibility(View.VISIBLE);
				}
			});
			

	       
	        information_txt_title_menu=(TextView)THIS.findViewById(R.id.txt_title_information);
	        information_List_Menu_Title.add(information_page_title);
	        information_txt_title_menu.setText(information_List_Menu_Title.get(0));
	        
	        
	        
	        
	        
	        
	        if(information_List_DATA_History.size()<=2)
	        	THIS.findViewById(R.id.img_back_list_information).setVisibility(View.INVISIBLE);
	        else
	        	THIS.findViewById(R.id.img_back_list_information).setVisibility(View.VISIBLE);
	        
	        THIS.findViewById(R.id.img_back_list_information).setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					
					if(information_List_DATA_History.size()>1)
					{
						
						
						Log.e("TG", "size : "+information_List_DATA_History.size());
						information_List_DATA_History.remove(information_List_DATA_History.size()-1);


						information_List_Menu_Title.remove(information_List_Menu_Title.size()-1);
						Log.e("TG", "Type : "+information_List_DATA_History.get(information_List_DATA_History.size()-1).Type);
						
						if(information_List_DATA_History.get(information_List_DATA_History.size()-1).Type.equals("child"))
							{
							
							Add_information_ChildToList(information_List_DATA_History.get(information_List_DATA_History.size()-1).Data,false);
							}
						else
						{
							
							Add_information_MainMenuToList(information_List_DATA_History.get(information_List_DATA_History.size()-1).Data,false);
						}
						
						
					}
					
					
					if(information_List_DATA_History.size()<=1)
						THIS.findViewById(R.id.img_back_list_information).setVisibility(View.INVISIBLE);
					
					Log.e("TG", "information_List_DATA_History size : "+information_List_DATA_History.size());
					
				}
			});
	   
	        information_MyArrList = new ArrayList<HashMap<String, Object>>();
	        THIS.findViewById(R.id.Lay_information).setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if(new ConnectInternet(THIS).checkInternetConnection())
					{
						//new LoadData_MainMenu().execute();
						new LoadData_information().execute();
					}
				}
			});
			
			
			
		}

		
		
		
		private void Add_information_ChildToList(String Data,Boolean AddNewData) {
			//Log.e("TG", "Add_Child_To_List=:" + Data);
			
			if(AddNewData){
			MenuData menudata = new MenuData();
			menudata.Data = Data;
			menudata.Type = "child";
			information_List_DATA_History.add(menudata);
			}
			Log.e("TG", "DATA=:" + Data);

			// =================================
			information_adapter = null;
			information_MyArrList.clear();
			if (information_adapter == null) {
				information_adapter = new informationListAdapter(THIS, information_MyArrList);
				information_lstView.setAdapter(information_adapter);
			}
			try {
				JSONArray JSONarray = new JSONArray(Data);
				for (int i = 0; i < JSONarray.length(); i++) {

					JSONObject jsonObj_information = JSONarray.getJSONObject(i);
					information_map = new HashMap<String, Object>();

					String tagName = "name" + (i + 1);
					String tagId = "page_id" + (i + 1);
					
					String tagName2 = "menu_title" + (i + 1);
					String tagId2 = "page_id" + (i + 1);
					

					try {information_map.put("Title", jsonObj_information.getString(tagName));} 
					catch (Exception ex) { 	try { information_map.put("Title", jsonObj_information.getString(tagName2));} catch (Exception ex2) {}}
					
					
					try {information_map.put("Id", jsonObj_information.getString(tagId));} 
					catch (Exception ex) {  try {information_map.put("Id", jsonObj_information.getString(tagId2));}catch (Exception ex2) {}}
					
					
					information_map.put("Stuck", "child");

					try {
						JSONArray jsonarray_child = jsonObj_information
								.getJSONArray("child");
						if (jsonarray_child.length() > 0)
							information_map.put("Type", "main");
						else
							information_map.put("Type", "child");

						information_map.put("Data", jsonarray_child.toString());
					} catch (Exception ex) {
						information_map.put("Type", "child");
						information_map.put("Data", "");
					}

					information_MyArrList.add(information_map);
					THIS.runOnUiThread(new Runnable() {
			            @Override
			            public void run() {
	                // This code will always run on the UI thread, therefore is safe to modify UI elements.
			            		information_adapter.notifyDataSetChanged();
			            }
			        });
					information_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, information_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());

				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			information_txt_title_menu.setText(information_List_Menu_Title.get(information_List_Menu_Title.size()-1));


		}
		private void Add_information_MainMenuToList(String Data,Boolean AddNewData) {
		//	Log.e("TG", "DATA Add main=:" + Data);

			// =================================
			information_adapter = null;
			information_MyArrList.clear();
			if (information_adapter == null) {
				information_adapter = new informationListAdapter(THIS, information_MyArrList);
				information_lstView.setAdapter(information_adapter);
			}
			try {
				JSONArray jsonarray_information = new JSONArray(Data);
				for (int i = 0; i < jsonarray_information.length(); i++) {

					JSONObject jsonObj_information = jsonarray_information
							.getJSONObject(i);

					String tagName = "name" + (i + 1);
					String tagId = "page_id" + (i + 1);
					
					information_map = new HashMap<String, Object>();
					try {information_map.put("Title", jsonObj_information.getString("main_menu"));} catch (Exception ex) {}
					try {information_map.put("Id", jsonObj_information.getString("page_id"));} catch (Exception ex) {}
					information_map.put("Stuck", "main_menu");

					try {
						JSONArray jsonarray_main_menu_child = jsonObj_information.getJSONArray("main_menu_child");
						if (jsonarray_main_menu_child.length() > 0)
							information_map.put("Type", "main");
						else
							information_map.put("Type", "child");

						information_map.put("Data", jsonarray_main_menu_child.toString());

					} catch (Exception ex) {
						information_map.put("Type", "child");
						information_map.put("Data", "");
					}
			    	 
					information_MyArrList.add(information_map);
					
					
					THIS.runOnUiThread(new Runnable() {
			            @Override
			            public void run() {
	                // This code will always run on the UI thread, therefore is safe to modify UI elements.
			            		information_adapter.notifyDataSetChanged();
			            }
			        });
					
					
					information_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, information_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());

				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try{
			information_txt_title_menu.setText(information_List_Menu_Title.get(information_List_Menu_Title.size()-1));
			} catch (Exception ex){Log.e("ERROR", ex.toString());};
		}
		
		
		
		
		
		public class informationListAdapter extends BaseAdapter {	
		    private Activity activity;
		    private LayoutInflater inflater=null;
		    ArrayList<HashMap<String, Object>> MyArrList = new ArrayList<HashMap<String, Object>>();
		    
		    public informationListAdapter(Activity a,ArrayList al ) {
		    	
		    	activity = a;
		        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		        MyArrList=al;
		       
		    }
		    
		    private class ViewHolder {
		    	private TextView txt_title;
				private ImageView img_arrow;
			}


		   
		    @Override
			public int getCount() {

		        return MyArrList.size();
		    }
		    @Override
		    public Object getItem(int position) {
		        return position;
		    }
		    @Override
		    public long getItemId(int position) {
		        return position;
		    }
		    
		    public View getView(final int position, View convertView, ViewGroup parent) {
		      
		    	View vi=convertView;
		    	final ViewHolder holder;
		    	
		        if(convertView==null)
		        {
			        vi = inflater.inflate(R.layout.item_mainmenu_listview2, null);
			        holder = new ViewHolder();
				   
				    holder.txt_title= (TextView)vi.findViewById(R.id.txt_title);
				    holder.img_arrow=(ImageView)vi.findViewById(R.id.img_arrow);
				   
				    
					vi.setTag(holder);	
			 	
			 		
			 		
			
			 		
			}else 
		    {
			
		    		holder = (ViewHolder)vi.getTag();
		    }
		            
		        holder.txt_title.setText(MyArrList.get(position).get("Title").toString());
		        if(	MyArrList.get(position).get("Data").toString().equals("")||
		        		MyArrList.get(position).get("Data").toString().equals("[]")	)
		        {
		        	holder.img_arrow.setVisibility(View.INVISIBLE);
		        }
		        else
		        	holder.img_arrow.setVisibility(View.VISIBLE);
		        //=================================SetData===================================

		        
			
			return vi;
		    }

		}
		class LoadData_information extends AsyncTask<Object, Integer, Object> {
			private boolean ONcancle=false;
			

			@Override
			protected void onCancelled() {
				// TODO Auto-generated method stub
				ONcancle=true;
				super.onCancelled();
			}

			@SuppressWarnings("null")
			@Override
			protected Object doInBackground(Object... params) {

				
				try {
					
					JSONObject jsonObj=null;
				
					jsonObj = new JSONObject(HttpGetJson.GetJson(Control.API_Information,"",""));
					
					
					
					//Log.e("tg", "LoadData_information:"+HttpGetJson.GetJson(Control.API_Information,"",""));
					
					JSONArray jsonarray_information=jsonObj.getJSONArray("information");
					
					// ===========Add to History
					MenuData menudata = new MenuData();
					menudata.Data = jsonObj.getJSONArray("information").toString();
					menudata.Type = "main";
					information_List_DATA_History.add(menudata);

					for (int i = 0; i < jsonarray_information.length(); i++) {

						JSONObject jsonObj_information = jsonarray_information
								.getJSONObject(i);

						
						information_map = new HashMap<String, Object>();
						try {information_map.put("Title", jsonObj_information.getString("main_menu"));} catch (Exception ex) {}
						try {information_map.put("Id", jsonObj_information.getString("page_id"));} catch (Exception ex) {}
						information_map.put("Stuck", "main_menu");
						
						
						//Log.e("TG","Title:"+jsonObj_information.getString("main_menu"));
						

						try {
							JSONArray jsonarray_main_menu_child = jsonObj_information
									.getJSONArray("main_menu_child");
							if (jsonarray_main_menu_child.length() > 0)
								information_map.put("Type", "main");
							else
								information_map.put("Type", "child");

							information_map.put("Data", jsonarray_main_menu_child.toString());

						} catch (Exception ex) {
							information_map.put("Type", "child");
							information_map.put("Data", "");
						}

						
						information_MyArrList.add(information_map); 
						 
						
						 
						
						

					}
				
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				
				
				return null;
			}

			@Override
			protected void onPreExecute() {

				
				information_MyArrList.clear();
			    
				if (information_adapter == null) {
					information_adapter = new informationListAdapter(THIS, information_MyArrList);
					information_lstView.setAdapter(information_adapter);
				}
				
				
				// =====================ProgressDialog==========================
				if(mProgressDialog == null)
				{
				mProgressDialog = new ProgressDialog(THIS);
				mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
				mProgressDialog.setMessage("Loading......");
				mProgressDialog.setCancelable(true);
				}
				
				if (mProgressDialog != null)
					mProgressDialog.show();
				
				super.onPreExecute();
			}

			@Override
			public void onProgressUpdate(Integer... progress) {

			
				
				
			}

			@Override
			protected void onPostExecute(Object result) {
				
				if(!ONcancle)
				{
		    	 information_lstView_params.height=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, information_MyArrList.size()*50, THIS.getResources().getDisplayMetrics());
		    	 information_txt_title_menu.setText(information_List_Menu_Title.get(information_List_Menu_Title.size()-1));

				
				//if (mProgressDialog != null)
					mProgressDialog.hide();
			
					THIS.runOnUiThread(new Runnable() 
					{
						
						  @Override
						  public void run() {
				             // This code will always run on the UI thread, therefore is safe to modify UI elements.
						      
						       information_adapter.notifyDataSetChanged();
						   }
				  });
				}	
				
				Log.e("TG", "information_List_DATA_History size : "+information_List_DATA_History.size());
			}

		}

		
		
		
		

}
